package cn.terminus.biz.customer.customlabel;

import cn.terminus.biz.customer.common.AbstractTerminusManager;
import cn.terminus.common.customer.bean.customlabel.dto.*;
import cn.terminus.data.customer.customlabel.dao.CustomLabelDao;
import cn.terminus.result.common.exception.DataAccessException;
import cn.terminus.result.common.page.TerminusPageAble;
import cn.terminus.result.common.page.TerminusPageInfo;
import cn.terminus.result.common.util.BeanCopyUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * (CustomLabel)表服务实现类
 *
 * @author makejava
 * @since 2021-07-08 11:18:52
 */
@Component
public class CustomLabelManager extends AbstractTerminusManager {
    @Autowired
    private CustomLabelDao customLabelDao;

    public Integer add(CustomLabelNewDto dto) throws DataAccessException {
        try {
            return customLabelDao.add(dto);
        } catch (Exception e) {
            logger.error("CustomLabelManager新增失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer update(CustomLabelEditDto dto) throws DataAccessException {
        try {
            return customLabelDao.update(dto);
        } catch (Exception e) {
            logger.error("CustomLabelManager更新失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<CustomLabelResultDto> gets(CustomLabelGetsDto dto) throws DataAccessException {
        try {
            return customLabelDao.gets(dto);
        } catch (Exception e) {
            logger.error("CustomLabelManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }


    public List<CustomLabelResultDto> query(CustomLabelQueryDto dto) throws DataAccessException {
        try {
            return customLabelDao.query(dto);
        } catch (Exception e) {
            logger.error("CustomLabelManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer delete(CustomLabelDeleteDto dto) throws DataAccessException {
        try {
            return customLabelDao.delete(dto);
        } catch (Exception e) {
            logger.error("CustomLabelManager删除失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public TerminusPageAble<CustomLabelResultDto> page(CustomLabelQueryDto dto, TerminusPageInfo page) throws DataAccessException {
        try {
            PageHelper.startPage(page.getCurrentPage(), page.getPageSize());
            Page<CustomLabelResultDto> result = (Page<CustomLabelResultDto>) customLabelDao.query(dto);
            return new TerminusPageAble<>(BeanCopyUtils.copy(result.getResult(), CustomLabelResultDto.class), page, result.getTotal());
        } catch (Exception e) {
            logger.error("CustomLabelManager分页查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer addMulti(List<CustomLabelNewDto> labelNewDtoList) throws DataAccessException {
        try {
            return customLabelDao.addMulti(labelNewDtoList);
        } catch (Exception e) {
            logger.error("CustomLabelManager新增失败，原因：", e);
            throw new DataAccessException(e);
        }
    }
}
